package com.zhiyou.brank.service.impl;

import java.util.ArrayList;
import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.zhiyou.brank.mapper.FlyScore;
import com.zhiyou.brank.service.FlyScoreService;
import com.zhiyou.model.FyScore;

@Service
public class FlyScoreServiceImpl implements FlyScoreService{
@Autowired
FlyScore flyScore;
	public List<FyScore> selectScoreOne(Integer student_id, Integer exam_id) {		
			FyScore selectScoreTwo = flyScore.selectScoreTwo(student_id, exam_id);
			List<FyScore> selectScoreOne1 = flyScore.selectScoreOne(student_id, exam_id);
			FyScore selectScoreTwo2;
			if (exam_id-1>0) {
				selectScoreTwo2 = flyScore.selectScoreTwo(student_id, exam_id-1);
				for (int i = 0; i < selectScoreOne1.size(); i++) {
					if (selectScoreOne1.get(i).getStudent_id()==selectScoreTwo.getStudent_id()) {
						selectScoreOne1.get(i).setScore_sum(selectScoreTwo.getScore_sum());
						selectScoreOne1.get(i).setResult(selectScoreTwo.getScore_sum()-selectScoreTwo2.getScore_sum());
					}
				}
			}				
		return selectScoreOne1;
	}
	public FyScore selectScoreTwo(Integer student_id, Integer exam_id) {
		return flyScore.selectScoreTwo(student_id, exam_id);
	}
	public List<FyScore> selectScoreThree(Integer class_id) {
		return flyScore.selectScoreThree(class_id);
	}
	/**
	 * 查询成绩以及总分
	 */
	public List<FyScore> selectScoreFour(Integer student_id) {
		List<FyScore> selectScoreFour = flyScore.selectScoreFour(1);
		List<FyScore> fyscore=new ArrayList<FyScore>();		
	c:	for (int i = 0; i < selectScoreFour.size(); i++) {
			if (selectScoreFour.get(i).getExam_id()!=selectScoreFour.get(i+1).getExam_id()) {
				 fyscore = flyScore.selectScoreOne(student_id, selectScoreFour.get(i).getExam_id());
				 FyScore selectScoreTwo = flyScore.selectScoreTwo(student_id, selectScoreFour.get(i).getExam_id());
				 fyscore.get(i).setScore_sum(selectScoreTwo.getScore_sum());
				 break c;
			}
			fyscore = flyScore.selectScoreOne(student_id, selectScoreFour.get(i).getExam_id());
			 FyScore selectScoreTwo = flyScore.selectScoreTwo(student_id, selectScoreFour.get(i).getExam_id());
			 fyscore.get(i).setScore_sum(selectScoreTwo.getScore_sum());
		}
		return fyscore;
	}
	@Override
	public void addScore(FyScore fyScore) {
		flyScore.addScore(fyScore);		
	}
	@Override
	public void updateScore(FyScore fyScore) {
		flyScore.updateScore(fyScore);
		
	}
	@Override
	public List<FyScore> selectScoreAll() {
		return flyScore.selectScoreAll();
	}
	@Override
	public FyScore selectScoreByName(String student_name, Integer exam_id) {
		return flyScore.selectScoreByName(student_name, exam_id);
	}
	@Override
	public void deleteScore(Integer score_id) {
		flyScore.deleteScore(score_id);		
	}
	
	
}
